/**
 * Created by Administrator on 2016/7/5.
 */
var setting = {
    check: {
        enable: true,
        chkStyle: "radio",
        radioType: "all"
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onCheck: onCheck
    }
};
var setting_holder = {
    check: {
        enable: true,
        chkStyle: "radio",
        radioType: "all"
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onCheck: onCheck_holder
    }
};

var setting_type = {
    check: {
        enable: true,
        chkStyle: "radio",
        radioType: "all"
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onCheck: onCheck_type
    }
};

function onCheck(e, treeId, treeNode) {
    if (treeNode.checked) {
        jQuery("#siteName").val(treeNode.name);
        jQuery("#siteId").val(treeNode.id);
    } else {
        jQuery("#siteName").val("");
        jQuery("#siteId").val("");
    }
    jQuery("#tree").hide();
}

function onCheck_holder(e, treeId, treeNode) {
    if (treeNode.checked) {
        jQuery("#holderName").val(treeNode.name);
        jQuery("#holder").val(treeNode.id);
    } else {
        jQuery("#holderName").val("");
        jQuery("#holder").val("");
    }
    jQuery("#tree_holder").hide();
}

function onCheck_type(e, treeId, treeNode) {
    if (treeNode.checked) {
        jQuery("#typeName").val(treeNode.name);
        jQuery("#type").val(treeNode.id);
        if (treeNode.id == 4 || treeNode.id == 5 || treeNode.id == 6 || treeNode.id == 8) {
            $("#siteNameSpan").html("");
            $("#siteName").removeClass("required");
        } else {
            $("#siteNameSpan").html("*");
            $("#siteName").addClass("required");
        }
    } else {
        jQuery("#typeName").val("");
        jQuery("#type").val("");
        $("#siteNameSpan").html("*");
        $("#siteName").addClass(required);
    }
    jQuery("#tree_type").hide();
}

var zTree = null;
function doPrint() {
    var holderName = $("#holderName").val();
    var cashBoxCode = $("#cashBoxCode").val();
    var type = $("#typeName").val();
    var siteName = $("#siteName").val();
    var createTime = $("#createTime").val();
    if (createTime == undefined || createTime == null || createTime == "") {
        createTime = new Date().Format("yyyy-MM-dd");
    }
    var assetCode = $("#assetCode").val();
    winname = window.open('', "_blank", '');
    bdhtml = window.document.body.innerHTML;
    sprnstr = "<!--startprint-->";
    eprnstr = "<!--endprint-->";
    prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
    prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
    var win = winname.document;
    win.body.innerHTML = prnhtml;
    win.getElementById("print_content").style.display = "table";
    win.getElementById("holderNamePrint1").innerHTML = holderName;
    win.getElementById("holderNamePrint2").innerHTML = holderName;
    win.getElementById("holderNamePrint3").innerHTML = holderName;
    win.getElementById("cashBoxCodePrint1").innerHTML = cashBoxCode;
    win.getElementById("cashBoxCodePrint2").innerHTML = cashBoxCode;
    win.getElementById("cashBoxCodePrint3").innerHTML = cashBoxCode;
    win.getElementById("typePrint1").innerHTML = type;
    win.getElementById("typePrint2").innerHTML = type;
    win.getElementById("typePrint3").innerHTML = type;
    win.getElementById("siteNamePrint1").innerHTML = siteName;
    win.getElementById("siteNamePrint2").innerHTML = siteName;
    win.getElementById("siteNamePrint3").innerHTML = siteName;
    win.getElementById("createTimePrint1").innerHTML = createTime;
    win.getElementById("assetCodePrint1").innerHTML = assetCode;
    winname.print();
    winname.close();
}

function ajaxService(url) {
    if (!$("#form1").valid()) {
        return;
    }
    $("#form1").showLoading();
    jQuery.ajax({
        'url': url,
        'data': $('#form1').serialize(),
        'dataType': 'json',
        'type': 'post',
        'success': function (rs) {
            var back_url = root + "/cashBox/list.do";
            if (rs.code == "500") {
                $("#form1").hideLoading();
                toastMessage(rs);
            } else {
                toastMessage(rs, back_url);
            }
        },
        'error': function () {
            $("#form1").hideLoading();
            bootbox.dialog({
                message: "系统繁忙，请稍后重试。",
                buttons: {
                    "success": {
                        "label": "确定",
                        "className": "btn-sm btn-primary"
                    }
                }
            });
        },
        'async': true
    });
}

openRfid();
function createRfid() {
    var code = jQuery("#cashBoxCode").val();
    var mydate = (new Date()).getTime();
    var rfid = "1124" + code + mydate;
    writeRfid(rfid);
}
function copyRfid() {
    var rfidCode = jQuery("#rfid").val()
    if (rfidCode != "") {
        writeRfid(rfidCode);
    }
}
